package com.waimai.mobile.ui.fragment;

import android.graphics.Color;
import android.support.v4.app.Fragment;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.waimai.mobile.R;

import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EFragment;
import org.androidannotations.annotations.ViewById;

/**
 * Created by lin on 2015/5/29.
 */

@EFragment(R.layout.fragment_restaurant_tab)
public class RestaurantTabFragment extends Fragment {

    @ViewById
    public LinearLayout tabOneLL;

    @ViewById
    public LinearLayout tabTwoLL;

    @ViewById
    public LinearLayout tabThreeLL;

    public OnTablSelectedListener listener;

    int clickedColor = Color.parseColor("#fe4e3f");

    int noClickedColor = Color.parseColor("#393939");


    @Click(R.id.tabOneLL)
    public void tabOneClick(){

        ImageView imageView = (ImageView) tabOneLL.findViewWithTag("image");
        TextView textView = (TextView) tabOneLL.findViewWithTag("text");

        imageView.setImageResource(R.mipmap.ic_line);
        textView.setTextColor(clickedColor);

        imageView = (ImageView) tabTwoLL.findViewWithTag("image");
        textView = (TextView) tabTwoLL.findViewWithTag("text");
        imageView.setImageDrawable(null);
        textView.setTextColor(noClickedColor);

        imageView = (ImageView) tabThreeLL.findViewWithTag("image");
        textView = (TextView) tabThreeLL.findViewWithTag("text");
        imageView.setImageDrawable(null);
        textView.setTextColor(noClickedColor);

        if(listener != null) {
            listener.onTablSelected(0, tabOneLL);
        }
    }

    @Click(R.id.tabTwoLL)
    public void tabTwoClick(){
        ImageView imageView = (ImageView) tabOneLL.findViewWithTag("image");
        TextView textView = (TextView) tabOneLL.findViewWithTag("text");

        imageView.setImageDrawable(null);
        textView.setTextColor(noClickedColor);

        imageView = (ImageView) tabTwoLL.findViewWithTag("image");
        textView = (TextView) tabTwoLL.findViewWithTag("text");
        imageView.setImageResource(R.mipmap.ic_line);
        textView.setTextColor(clickedColor);

        imageView = (ImageView) tabThreeLL.findViewWithTag("image");
        textView = (TextView) tabThreeLL.findViewWithTag("text");
        imageView.setImageDrawable(null);
        textView.setTextColor(noClickedColor);
        if(listener != null) {
            listener.onTablSelected(1, tabTwoLL);
        }
    }

    @Click(R.id.tabThreeLL)
    public void tabThreeClick(){
        ImageView imageView = (ImageView) tabOneLL.findViewWithTag("image");
        TextView textView = (TextView) tabOneLL.findViewWithTag("text");

        imageView.setImageDrawable(null);
        textView.setTextColor(noClickedColor);

        imageView = (ImageView) tabTwoLL.findViewWithTag("image");
        textView = (TextView) tabTwoLL.findViewWithTag("text");
        imageView.setImageDrawable(null);
        textView.setTextColor(noClickedColor);

        imageView = (ImageView) tabThreeLL.findViewWithTag("image");
        textView = (TextView) tabThreeLL.findViewWithTag("text");
        imageView.setImageResource(R.mipmap.ic_line);
        textView.setTextColor(clickedColor);
        if(listener != null) {
            listener.onTablSelected(2, tabTwoLL);
        }
    }

    public void selectItem(int position){
        switch (position){
            case 0:
                tabOneClick();
                break;
            case 1:
                tabTwoClick();
                break;
            case 2:
                tabThreeClick();
                break;
        }
    }

    public void setOnTabSelectedListtener(OnTablSelectedListener listener){
        this.listener = listener;
    }

    public interface OnTablSelectedListener{

        public void onTablSelected(int position, ViewGroup view);

    }

}
